﻿<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>会员申请</title>
		<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
		<link href="../css/style.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/utils.js"></script>
		<script type="text/javascript" src="../js/checkLogin.js"></script>
		<script type="text/javascript" src="../js/jquery.pager.js"></script>
		<script type="text/javascript" src="../js/pagination.js"></script>
		<script type="text/javascript" src="../js/shopSelecter.js"></script>
		<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
		<script type="text/javascript" src="../js/find.js"></script>
		<script type="text/javascript" src="../js/dataTable.js"></script>
		<script type="text/javascript">
			var _applyId = null;
			var _pagination = null;
			$(function() {
				$('.doubledate').kuiDate({
					className : 'doubledate',
					isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
				});
				initShopSelecter();
			});

			/**
			 * 初始化店面选择器
			 */
			function initShopSelecter() {
				refreshInput($(".serWrapper"));
				$("#shopIsChoosed").removeAttr("checked");
				$("#shopName").attr("disabled", "disabled");

				$("#shopIsChoosed").bind("click", function() {
					var checked = $(this).attr("checked");
					if (checked) {
						$("#shopName").removeAttr("disabled");
					} else {
						$("#shopName").attr("disabled", "disabled");
						$("#shopName").empty();
					}
				});
			}

			/**
			 * 打开添加层
			 */
			function openAddPanel(applyId) {
				loadDetail(applyId);
				$("#addPanel").show();
				$("#listPanel").hide();
			}

			function loadMemberLeave(shopId) {
				var $select = $("#memberLeave");
				$select.empty();
				$.get('../memberLevel/find/memberLevelList/0/10?shopId=' + shopId, function(message) {
					if (IsEmpty(message)) {
						artError('没有查询到数据！');
						return;
					}
					if (message.state === 0) {
						//"ID","ShopID","Code","Name","ValidDay","Status","AcceDiscount",
						//"WorkDiscount", "MemberFee", "Deposit", "discount", "sys", "shopName"
						for (var i = 0; i < message.result.data.length; i++) {
							var id = getHtmlString(getHeadIndexValue(i, message, 'ID'));
							var name = getHtmlString(getHeadIndexValue(i, message, 'Name'));
							var option = "<option value='" + id + "'>" + name + "</option>";
							$select.append($(option));
						}

					} else if (message.state == 1) {
						artAlert(message.msg);
					} else {
						checkStateShowErrorMsgAndDealResult(JSON.stringify(message));
					}
				}, 'json');
			}

			/**
			 * 加载详细数据
			 */
			function loadDetail(applyId) {
				_applyId = applyId;
				$.get('../memberapply/find/detail/' + applyId, function(message) {
					if (IsEmpty(message)) {
						artError('没有查询到数据！');
						return;
					}
					if (message.state === 0) {
						//"shopID","customerName","sex","birthday","mp","email","IDNumber",
						//"zipCode","address","createFileTime","memberFee",license
						$("#shopName1").val(getHtmlString(getHeadIndexValue(0, message, 'shopName')));
						$("#customerName").val(getHtmlString(getHeadIndexValue(0, message, 'customerName')));
						var sex = getHtmlString(getHeadIndexValue(0, message, 'sex'));
						if (sex == 0) {
							$("#sex").val('男');
						} else {
							$("#sex").val('女');
						}
						$("#birthday").val(getHtmlString(getHeadIndexValue(0, message, 'birthday')));
						$("#mp").val(getHtmlString(getHeadIndexValue(0, message, 'mp')));
						$("#email").val(getHtmlString(getHeadIndexValue(0, message, 'email')));
						$("#IdNumber").val(getHtmlString(getHeadIndexValue(0, message, 'IDNumber')));
						$("#address").val(getHtmlString(getHeadIndexValue(0, message, 'address')));
						$("#createFileTime").val(getHtmlString(getHeadIndexValue(0, message, 'createFileTime')));
						$("#memberFee").val(getHtmlString(getHeadIndexValue(0, message, 'memberFee')));
						$("#zipCode").val(getHtmlString(getHeadIndexValue(0, message, 'zipCode')));
						$("#license").val(getHtmlString(getHeadIndexValue(0, message, 'license')));

						var shopId = getHtmlString(getHeadIndexValue(0, message, 'shopID'));
						loadMemberLeave(shopId);
					} else if (message.state == 1) {
						artAlert(message.msg);
					} else {
						checkStateShowErrorMsgAndDealResult(JSON.stringify(message));
					}
				}, 'json');
			}

			function del(applyId) {
				artConfirm("是否删除该会员申请记录？", function() {
					$.get('../memberapply/delete/' + applyId, function(message) {
						if (IsEmpty(message)) {
							artError('没有查询到数据！');
							return;
						}
						if (message.state === 0) {
							artSuccess("删除成功");
							closeAddPanel();
							_pagination.reload();
						} else if (message.state == 1) {
							artAlert(message.msg);
						} else {
							checkStateShowErrorMsgAndDealResult(JSON.stringify(message));
						}
					}, 'json');
				});
			}

			function check() {
				artConfirm("确定审核该用户？", function() {
					var replyContent = $("#replyContent").val();
					var leaveId = $("#memberLeave").val();
					var mp = $("#mp").val();

					$.get('../memberapply/check1/' + _applyId, {
						replyContent : replyContent,
						leaveId : leaveId,
						mp : mp
					}, function(message) {
						if (IsEmpty(message)) {
							artError('没有查询到数据！');
							return;
						}
						if (message.state === 0) {
							artSuccess("审核成功");
							closeAddPanel();
							_pagination.reload();
						} else if (message.state == 1) {
							artAlert(message.msg);
						} else {
							checkStateShowErrorMsgAndDealResult(JSON.stringify(message));
						}
					}, 'json');
				});

			}

			/**
			 * 关闭添加层
			 */
			function closeAddPanel() {
				$("#addPanel").hide();
				$("#listPanel").show();
			}

			/**
			 * 查找
			 */
			function search() {
				var shopId = $("#shopName").val();
				if (shopId == null)
					shopId = '';
				var startDate = $("#startDate").val();
				var endDate = $("#endDate").val();
				var customerName = $("#searchName").val();
				var mp = $("#searchMp").val();

				_pagination = new Pagination({
					url : '../memberapply/find/all/',
					data : {
						shopId : shopId,
						startDate : startDate,
						endDate : endDate,
						customerName : customerName,
						mp : mp
					},
					success : printDataToPage,
					pageSize : 10
				});
			}

			/**
			 * 将数据打印到页面
			 */
			function printDataToPage(message) {
				dataTable({
					tbodyId : 'memberApplyList',
					heads : ["shopName", "createFileTime", "customerName", "sex", "birthday", "mp", "cityName", "applyID"],
					rst : message,
					sup : {
						id : "sup",
						template : "共 [index] 条"
					},
					handler : [{
						col : 7,
						f : detail
					}, {
						col : 3,
						f : sexHandler
					}]
				});
			}

			function sexHandler(heads, row) {
				var sex = heads[0];
				if (sex == 0) {
					return '男';
				} else {
					return '女';
				}
			}

			function detail(heads, row) {
				var detail = "<input type='button' class='common_btn' value='详情' onclick=\"openAddPanel(" + heads[0] + ")\">";
				var del = "<input type='button' class='common_btn del' value='删除' onclick=\"del(" + heads[0] + ")\">";
				return detail + del;
			}

		</script>

	</head>
	<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>

		<!-- 选择 商铺名称的列表 -->
		<div id="shopListPanel_yinying" class="yinying" style="z-index:100;"></div>
		<div id="shopListPanel" class="hideDiv">
			<div style="float: right; margin-bottom: 5px; width: 20px; height: 20px; line-height: 20px; text-align: center; background-color: #eee; margin-bottom: 5px; border: 1px solid #ccc;">
				<span id="shopListPanel_close" style="cursor: pointer; font-size: 14px;">X</span>
			</div>
			<div class="bottom_search">
				<div class="serWrapper" >
					<input type="text" id="shopListPanel_searchName" class="txt" >
					<strong class="refresh" onclick="$(this).prev().val('')">清空</strong>
				</div>
				<input type="button" id="shopListPanel_search"
				style="width: auto; margin-left: 5px;" value="查询"
				class="common_btn">
			</div>
			<table cellpadding="4" cellspacing="0" border="1" width="100%">
				<thead>
					<tr>
						<th>店面ID</th>
						<th>店面名称</th>
						<th>电话</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="shopListPanel_data" ></tbody>
			</table>
			<div id="shopPager" class="pager"></div>
		</div>

		<div class="container" id="container">
			<!-- 会员申请 -->
			<div class="container_R fr" id="addPanel" style="display: none;">
				<div class="place">
					会员申请>详情
					<a class="goHome"  href="javaScript:void(0);" onclick='closeAddPanel()'>返回</a>
				</div>
				<div class="member_search">
					<p>
						<label><span>店面名称:</span>
							<input type="text" id="shopName1" readonly="readonly" style="width: 390px;"  />
						</label>
						<label><span>车牌号:</span>
							<input id="license" type="text" readonly="readonly"  />
						</label>
					</p>
					<p>
						<label><span>客户姓名:</span>
							<input id="customerName" type="text" readonly="readonly"  />
						</label>
						<label><span>性别:</span>
							<input type="text" id="sex" readonly="readonly"  />
						</label>
						<label><span>出身日期:</span>
							<input type="text" id="birthday" readonly="readonly"  />
						</label>
					</p>
					<p>
						<label><span>手机:</span>
							<input type="text" id="mp"/>
						</label>
						<label><span>电子邮件:</span>
							<input type="text" id="email" readonly="readonly"  />
						</label>
						<label><span>身份证号码:</span>
							<input type="text" id="IdNumber" readonly="readonly"  />
						</label>
					</p>
					<p>
						<label><span>邮编:</span>
							<input type="text" id="zipCode" readonly="readonly"  />
						</label>
						<label><span>地址:</span>
							<input type="text" id="address" readonly="readonly" style="width: 390px;" />
						</label>
					</p>
					<p>
						<label><span>建档时间:</span>
							<input type="text" id="createFileTime" readonly="readonly"  />
						</label>
						<label><span>会费:</span>
							<input type="text" id="memberFee" readonly="readonly"  />
						</label>
						<label><span>会员级别:</span>
							<select id="memberLeave">
								<option>级别一</option>
								<option>级别二</option>
								<option>级别三</option>
							</select> </label>
					</p>
					<p>
						<label><span>回复内容: </span> 							<textarea id="replyContent" style="width:640px; height: 60px;"></textarea> </label>

					</p>
				</div>
				<div class="submit_btn">
					<input type="button" value="审批" onclick="check()" class="common_btn"onclick="validate()">
					<input type="button" value="取消" onclick="closeAddPanel()" class="common_btn check_btn"onclick="validate()">
				</div>
			</div>

			<!-- 会员列表 -->
			<div class="container_R fr" id="listPanel" style="padding: 17px; width: 773px;">
				<div class="place">
					会员申请
				</div>
				<div class="member_search">
					<P>
						<span>
							<input type="checkbox" id="shopIsChoosed" style="width: auto; height: auto;border:none;">
							店面： </span>
						<select class="shopName" id="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
						<span>开始日期：</span>
						<input type="text" readonly
						class="doubledate ipticon" id="startDate" />
						<span>结束日期：</span>
						<input type="text" readonly
						class="doubledate ipticon" id="endDate" />
					</P>
					<p>
						<span>姓名：</span>
						<input type="text" id="searchName" />
						<span>手机：</span>
						<input type="text" id="searchMp" />
						<input type="button" value="查询" class="btn" onclick="search();">
					</p>
				</div>
				<table width="100%" class="member_list" cellpadding="0"
				cellspacing="1" border="0">
					<caption>
						<strong>会员列表 <span id="sup">共0条</span></strong>
					</caption>
					<thead>
						<tr>
							<th>店面</th>
							<th>申请日期</th>
							<th>姓名</th>
							<th>性别</th>
							<th>出生日期</th>
							<th>手机号</th>
							<th>归属地</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="memberApplyList"></tbody>
				</table>
				<div id="pager" style="float: right;"></div>
			</div>
			<div class="fc"></div>
		</div>
		<!-- InstanceEndEditable -->
		<script type="text/javascript" src="../js/header.js"></script>
		<script type="text/javascript" src="../js/left.js"></script>
		<script type="text/javascript" src="../js/footer.js"></script>
		<script type="text/javascript">
			showTab(10, 1);
		</script>
	</body>
	<!-- InstanceEnd -->
</html>
